﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CL.Business.BLL;
using CL.Business.Entity;
using CL.Enum.Common;
using CL.Enum.Common.Lottery;
using CL.Tools.Common;
using CL.View.Entity.Business;
using CL.View.Entity.Union;

namespace CL.UnionWeb.union
{
    public partial class Brokerage : BasePage
    {
        protected int accountid;
        protected string currentMonth = string.Empty;
        public const int months = 12;  //默认可查看12个月内的预计分成
        protected List<Union_BrokerageViewModel> listItem = new List<Union_BrokerageViewModel>();
        public static AccountEntity Entity = new AccountEntity();
        public static SettleDayBLL bll = new SettleDayBLL();
        public double ExceptFare = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "推广联盟-预计分成";
            currentMonth = QPRequest.GetQueryString("currentMonth");
            if (string.IsNullOrEmpty(currentMonth))
                currentMonth = DateTime.Now.ToString("yyyy-MM");

            Entity = base.GetUnionInfo();
            var accountid = Entity.AccountID;
            var Entitys = bll.GetSettleDayBll(accountid, currentMonth);

            foreach (var item in Entitys)
            {
                Union_BrokerageViewModel tmpItem = new Union_BrokerageViewModel();
                tmpItem.Day = item.Day;
                tmpItem.BuyAmount = Math.Round((double)item.BuyAmount / 100, 2);
                tmpItem.RebateNum = item.RebateNum;
                tmpItem.FanliAmount = Math.Round(tmpItem.BuyAmount * tmpItem.RebateNum / 10000, 2);
                ExceptFare += tmpItem.FanliAmount;
                listItem.Add(tmpItem);
            }

            List<string> listYearMonth = new List<string>();
            for ( int i = months; i > 0; --i )
            {
                listYearMonth.Add(DateTime.Now.AddMonths(i - months).ToString("yyyy-MM"));
            }
            yearMonth.DataSource = listYearMonth;
            yearMonth.DataBind();

            new RecordBLL().InsertEntity(new Business.Entity.RecordEntity()
            {
                AccountID = Entity.AccountID,
                RecordTime = DateTime.Now,
                RecordRemark = string.Format("查看 {0} 预计分成 ", currentMonth),
                RecordType = 6
            });
        }
    }
}